package dataProces;

import java.sql.ResultSet;
import java.util.HashMap;

public class DBS {
    FileOpera fio = new FileOpera();

    public HashMap<String, String> dataQueries(String table, String key, String val) {
        DBC dbc = new DBC();
        HashMap<String, String> idiom = null;
        String sql = "select * from " + table + " where " + key + "='" + val + "';";
        try {
            dbc.mysqlConnection();
            ResultSet rSet = dbc.mysqlQuery(sql);
            if (rSet.next()) {
                idiom = new HashMap<>();
                for (int i = 0; i < rSet.getMetaData().getColumnCount(); i++)
                    idiom.put(rSet.getMetaData().getColumnName(i + 1), rSet.getString(i + 1));
            }
        } catch (Exception e) {
            fio.logFile("数据查询异常:" + e.getMessage());
        } finally {
            dbc.mysqlClose();
        }
        return idiom;
    }
}
